BIN = tree
BINDIR = ../bin/
DEBUG ?= no
CFLAGS=
LDFLAGS=

ifeq ($(DEBUG),yes)
	CFLAGS= $(CFLAGS) -g
endif

CC = g++
SUBDIR = .
SRC = $(foreach dir, $(SUBDIR), $(wildcard $(dir)/*.cc))
OBJ = $(SRC:.cc=.o)
DEP = .depend

.PHONY : all
all: .depend $(BIN)

%.o: %.cc
	$(CC) $(CFLAGS) -c $< -o $@
	
$(BIN):	$(DEP) $(OBJ)
	$(CC) $(OBJ) -o $(BINDIR)$@ $(LDFLAGS)

.PHONY : clean
clean:
	rm -f *.o $(DEP)
	
.PHONY : mrproper
mrproper: clean
	rm -f $(BINDIR)$(BIN) .depend .DS_Store

.PHONY: archive
archive: mrproper
	@echo "Archivage dans ../archive"
	@tar -czf ../archive/src-`date +%Hh%Mm%S-%d-%b-%y`.tar.gz .

$(DEP): $(SRC)
	@echo "Génération des dépendances"
	@$(CC) $(CFLAGS) -MM $(SRC) > $@
	
-include $(DEP)
